;(function (call) {
    var main = {
        mapId: "tjMap",
        init: function () {
			this.initDatePicker();
            this.initProduct();
			this.bindevent();
        },
		bindevent:function(){
			 var that = this;
            //chauxn 
            $(".query").unbind("click").bind("click", function () {
                that.initProduct();
            })
			$(".product-pic-download").unbind("click").bind("click",function(){
				Html2Canvas.Save($(".product-pic-view"), function () { });
			})
			//往前
			$(".product-pic-prev").unbind("click").bind("click",function(){
				let date = $(".product-query #product-startdatepicker").IDatePicker().getVal()+":00";
				let newDate = new Date(new Date(date).getTime() - 1000*60*5).format("yyyy-MM-dd hh:mm:00");
				$(".product-query #product-startdatepicker").IDatePicker().setVal(newDate);
				that.initProduct();
			})

			//往后
			$(".product-pic-next").unbind("click").bind("click",function(){
				let date = $(".product-query #product-startdatepicker").IDatePicker().getVal()+":00";
				let newDate = new Date(new Date(date).getTime() + 1000*60*5).format("yyyy-MM-dd hh:mm:00");
				$(".product-query #product-startdatepicker").IDatePicker().setVal(newDate);
				that.initProduct();
			})
		},
		// 初始化时间控件
        initDatePicker: function () {
            var that = this;
			var date = $("#datepicker-autostat .datepicker-date span").text()+":00"
            var time = date?new Date((new Date(date).getTime() - 1000*60*5)).format("yyyy-MM-dd hh:mm:00"):new Date().format("yyyy-MM-dd 08:00:00");
            $("#product-startdatepicker").val(time);
            $.IDate(".product-query_time",{})
        },
        // 获取产品图
        initProduct: function () {
            var that = this;
			debugger;
			var id = $("#modal_autostat ul[iid='STREAM'] .active").data("eleid");
			var time = $(".product-query #product-startdatepicker").IDatePicker().getVal() + ":00";
			var querytime = new Date(time).format('yyyyMMddhhmm00');
			loading.add();
            $.ajax({
				url: "/fjots/findstreamElementPng?time="+querytime+"&element="+id,
				type: 'GET',
				async: false
			}).done(function (res) {
				loading.remove();
				if(res && res !=""){
					$(".model-pic").attr("src","data:image/png;base64,"+res);
				}
			})
        }
    };
    if (typeof call === 'function') {
        window.autoproductPic = main;
        call(main);
    }
})(function (main) {
     main.init();
});